<import template="/panel/_header" />
<div class="page-container">
    <div class="main-content">
        <div class="page-title">

            <div class="title-env">
                <h1 class="title">用户中心</h1>
                <p class="description">个人资料&用户信息</p>
            </div>

            <div class="breadcrumb-env">
                <ol class="breadcrumb bc-1">
                    <li>
                        <a href="/member"><i class="fa-home"></i>主页</a>
                    </li>
                    <li>
                        <a href="javascript:;">用户中心</a>
                    </li>
                    <li class="active">
                        <strong>个人资料</strong>
                    </li>
                </ol>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <i class="fa fa-angle-right"></i>
                    </div>
                    <div class="panel-body">
                        <div class="form-group">
                            <p>用户名：{$user->nickname}</p>
                            <p>邮箱：{$user->email}&nbsp;<if condition="$is_verification">&nbsp;&nbsp;您还没有校验邮箱地址！（<a href="javascript:;" id="resend_verification">重新发送校验码</a>）<else>(该邮箱地址已校验)</if></p>
                            <p>套餐：<span class="label label-info">{$user->getPlan()}</span>
                                <if condition="$user->plan == 'A'">
                                    &nbsp;&nbsp;您为免费体验账户，流量将不会每月重置，升级到会员账户即可提升流量限额。
                                </if>
                            </p>
                            <p>账户余额：{$user->money} 元 </p>
                            <hr/>
                            <p>您的总流量：{(\Helper\Utils::flowAutoShow($user->transfer))}</p>
                            <p>可用流量：<span id="slaTransfer">{(\Helper\Utils::flowAutoShow($user->transfer - ($user->flow_up+$user->flow_down)))}</span></p>
                            <p>已用流量：<span id="useTransfer">{(\Helper\Utils::flowAutoShow($user->flow_up+$user->flow_down))}</span></p>
                            <p><button class="btn btn-danger btn-sm" id="check_enable">刷新账户状态（当前：{$enable_status}）</button></p>
                            <!--
                            <p><button class="btn btn-danger btn-sm" id="deleteMe">删除我的账户</button></p>
                            -->
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script type="text/javascript">
            $("#deleteMe").on('click', function(){
                var flag = confirm("真的要删除吗？此操作一去不复返哦~");
                if(flag) {
                    $(".main-content").fadeTo('slow',0.6);
                    $.ajax({
                        url: "/member/deleteMe.json",
                        type: "POST",
                        data: {"delete": 1},
                        dataType: "json",
                        success: function(result) {
                            if(result.code != 200) {
                                showToastr(result.message, 0, '系统错误');
                                return;
                            }
                            if(result.data.error == 0) {
                                showToastr(result.data.message, 0);
                                setTimeout('window.location.href="/auth/login#login"', 3000);
                            } else {
                                showToastr('不好意思，服务端妹纸好像舍不得你，不然你在试一次？（删除失败）', 0);
                                $(".main-content").fadeTo('slow', 1);
                            }
                        },
                        error: function(Xhr) {
                            showToastr('请求服务器失败', 0);
                            $(".main-content").fadeTo('slow', 1);
                        }
                    });
                }
            });
            $("#resend_verification").on('click', function(){
                var but = $(this);
                but.attr("disabled", "disabled").html("60秒才能发送一次");
                $.ajax({
                    url: "/auth/resend.json",
                    type: "POST",
                    data: {"auth": 'y'},
                    dataType: "json",
                    success: function(result) {
                        if(result.code != 200) {
                            showToastr(result.message, 0, '系统错误');
                            return;
                        }
                        if(result.data.error == 0) {
                            showToastr(result.data.message, 0);
                            setTimeout('but.removeAttr("disabled").html("重新发送校验码");', 55000);
                        } else {
                            showToastr('发送邮件失败', 0);
                        }
                    },
                    error: function(Xhr) {
                        showToastr('请求服务器失败', 0);
                        $(".main-content").fadeTo('slow', 1);
                    }
                });
            });
            $("#check_enable").on('click', function () {
                var but = $(this);
                but.attr("disabled", "disabled").html("确认中");
                $.ajax({
                    url: "/user/checkEnable.json",
                    type: "POST",
                    data: {},
                    dataType: "json",
                    success: function(result) {
                        if(result.code != 200) {
                            showToastr(result.message, 0, '系统错误');
                            return;
                        }
                        if(result.data.enable == 1) {
                            showToastr('账户已经是启用状态，如果您之前是停用状态，过30秒后尝试即可连接上服务器。谢谢', 0);
                        } else {
                            showToastr('账户已经被停用', 0);
                        }
                        var stat = result.data.enable == 1 ? "启用" : "停用";
                        but.removeAttr("disabled").html("刷新账户状态（当前：" + stat +")");
                    },
                    error: function(Xhr) {
                        showToastr('请求服务器失败', 0);
                        $(".main-content").fadeTo('slow', 1);
                    }
                });

            })
        </script>
        <import template="/panel/_copyright" />
    </div>
</div>
<import template="/panel/_footer" />